package com.lkm.market2_0.m_imple.steelyardserver.server;

import com.lkm.javatool.NumberHelp;

import java.util.Arrays;




public class CMDEntity {


    private CMDEntity(){};
    

    public static CMDEntity parserByData(String steelyardMac,byte[] data){
        CMDEntity cmdEntity=new CMDEntity();

        cmdEntity.cmd=data[0];

        int num = NumberHelp.bytesToIntDesc(new byte[]{ data[1], data[2]});
        cmdEntity.num=num;
        
        if(cmdEntity.cmd==cmd_ok||cmdEntity.cmd==cmd_fail){
            cmdEntity.isTickCMD=true;
        }else{
            cmdEntity.isTickCMD=false;
        }

        cmdEntity.num=num;

        
        cmdEntity.data = Arrays.copyOfRange(data ,3,data.length) ;


        cmdEntity.steelyardMac=steelyardMac;

        return cmdEntity;
    }

    private static byte cmd_ok=0x00;
    private static byte cmd_fail=(byte) 0xff;






    private static byte cmd_getTradeInfo=0x06;

    private String steelyardMac;
    

    private byte cmd ;


    private boolean isTickCMD;

    
    
    
    private int num;

    
    private byte[] data;

    public boolean isGetTradeInfo(){
        return cmd==cmd_getTradeInfo;
    }





//            return new ReceiverDataTradeInfoHandle(num,TradeInfoEntity.class.hashCode());





    public boolean isTickCMD(){
        return isTickCMD;
    }
    public boolean isTickOK(){
        return cmd==cmd_ok;
    }

    public boolean isTickFail(){
        return cmd==cmd_fail;
    }


    public int getNum() {
        return num;
    }

    

    public byte[] getData() {
        return data;
    }


    

    public boolean is32Zero() {
        if(num!=0)return false;
        int n =  num;

        for (int i = 0; i <data.length; i++) {
            n+=data[i];
        }

        return n==0;
    }

    public byte getCmd() {
        return cmd;
    }

    public String getSteelyardMac() {
        return steelyardMac;
    }

    public void setSteelyardMac(String steelyardMac) {
        this.steelyardMac = steelyardMac;
    }
}
